package io.gitee.yaoshanli.engine.service.impl;

import io.gitee.yaoshanli.engine.db.JwDbHelper;
import io.gitee.yaoshanli.engine.model.WfProcessModel;
import io.gitee.yaoshanli.engine.service.IProcessService;
import io.gitee.yaoshanli.engine.utils.DateUtils;
import io.gitee.yaoshanli.engine.utils.StringUtils;

import java.util.List;

public class ProcessService implements IProcessService {

    @Override
    public boolean saveProcess(String wf_id, String task_id, String node_id, String desc,String oper) {
        String guid= StringUtils.GUID();
        String sql="insert into jw_wf_process (id,wf_id,task_id,node_id,description,create_by,create_time)" +
                " values (?,?,?,?,?,?,?) ";
        Object[] args = new Object[]{guid,wf_id,task_id,node_id,desc,oper, DateUtils.getNowDate()};
        if(JwDbHelper.update(sql,args)>0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    @Override
    public boolean delete(String wf_id, String task_id) {
        String sql="delete from jw_wf_process where wf_id=? and task_id=?";
        Object[] args = new Object[]{wf_id,task_id};
        return JwDbHelper.update(sql,args)>0;
    }

    @Override
    public boolean delete(String task_id) {
        String sql="delete from jw_wf_process where task_id=?";
        Object[] args = new Object[]{task_id};
        return JwDbHelper.update(sql,args)>0;
    }

    @Override
    public List<WfProcessModel> getList(String task_id) {
        String sql="select * from jw_wf_process where task_id=? order by create_time desc";
        Object[] args = new Object[]{task_id};
        return JwDbHelper.queryList(WfProcessModel.class,sql,args);
    }

}
